BEGIN;
CREATE TABLE `myhomework_user` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `auth_user_id` integer NOT NULL,
    `student_id` varchar(30) NOT NULL,
    `school` varchar(30) NOT NULL,
    `major` varchar(30) NOT NULL,
    `name` varchar(30) NOT NULL,
    `email` varchar(75) NOT NULL,
    `group_id` integer,
    `last_updated_time` datetime NOT NULL
)
;
ALTER TABLE `myhomework_user` ADD CONSTRAINT `auth_user_id_refs_id_11c09135` FOREIGN KEY (`auth_user_id`) REFERENCES `auth_user` (`id`);
CREATE TABLE `myhomework_group` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `administrator_id` integer NOT NULL,
    `name` varchar(30) NOT NULL,
    `last_updated_time` datetime NOT NULL
)
;
ALTER TABLE `myhomework_group` ADD CONSTRAINT `administrator_id_refs_id_b8f9b74` FOREIGN KEY (`administrator_id`) REFERENCES `myhomework_user` (`id`);
ALTER TABLE `myhomework_user` ADD CONSTRAINT `group_id_refs_id_31c0524a` FOREIGN KEY (`group_id`) REFERENCES `myhomework_group` (`id`);
CREATE TABLE `myhomework_homework` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `name` varchar(30) NOT NULL,
    `content` longtext NOT NULL,
    `pub_date` datetime NOT NULL,
    `deadline` datetime NOT NULL,
    `last_updated_time` datetime NOT NULL,
    `type` varchar(30) NOT NULL
)
;
CREATE TABLE `myhomework_homeworksubmitedinfo` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `last_updated_time` datetime NOT NULL,
    `homework_id` integer NOT NULL,
    `src` varchar(1024) NOT NULL,
    `url` varchar(1024) NOT NULL,
    `score` integer NOT NULL,
    `rank` integer NOT NULL
)
;
ALTER TABLE `myhomework_homeworksubmitedinfo` ADD CONSTRAINT `homework_id_refs_id_3a5aea20` FOREIGN KEY (`homework_id`) REFERENCES `myhomework_homework` (`id`);
CREATE TABLE `myhomework_personalhomeworksubmited` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `homework_submited_info_id` integer NOT NULL,
    `user_id` integer NOT NULL
)
;
ALTER TABLE `myhomework_personalhomeworksubmited` ADD CONSTRAINT `user_id_refs_id_586b50b7` FOREIGN KEY (`user_id`) REFERENCES `myhomework_user` (`id`);
ALTER TABLE `myhomework_personalhomeworksubmited` ADD CONSTRAINT `homework_submited_info_id_refs_id_22f0483f` FOREIGN KEY (`homework_submited_info_id`) REFERENCES `myhomework_homeworksubmitedinfo` (`id`);
CREATE TABLE `myhomework_contribution` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `user_id` integer NOT NULL,
    `contribution` integer NOT NULL
)
;
ALTER TABLE `myhomework_contribution` ADD CONSTRAINT `user_id_refs_id_ba1beb6` FOREIGN KEY (`user_id`) REFERENCES `myhomework_user` (`id`);
CREATE TABLE `myhomework_teamworksubmited_contributions` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `teamworksubmited_id` integer NOT NULL,
    `contribution_id` integer NOT NULL,
    UNIQUE (`teamworksubmited_id`, `contribution_id`)
)
;
ALTER TABLE `myhomework_teamworksubmited_contributions` ADD CONSTRAINT `contribution_id_refs_id_4a9f6a74` FOREIGN KEY (`contribution_id`) REFERENCES `myhomework_contribution` (`id`);
CREATE TABLE `myhomework_teamworksubmited` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `homework_submited_info_id` integer NOT NULL,
    `group_id` integer NOT NULL
)
;
ALTER TABLE `myhomework_teamworksubmited` ADD CONSTRAINT `homework_submited_info_id_refs_id_2b308f55` FOREIGN KEY (`homework_submited_info_id`) REFERENCES `myhomework_homeworksubmitedinfo` (`id`);
ALTER TABLE `myhomework_teamworksubmited` ADD CONSTRAINT `group_id_refs_id_16de66c4` FOREIGN KEY (`group_id`) REFERENCES `myhomework_group` (`id`);
ALTER TABLE `myhomework_teamworksubmited_contributions` ADD CONSTRAINT `teamworksubmited_id_refs_id_47051f21` FOREIGN KEY (`teamworksubmited_id`) REFERENCES `myhomework_teamworksubmited` (`id`);
CREATE TABLE `myhomework_assessment` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `userA_id` integer NOT NULL,
    `userB_id` integer NOT NULL,
    `score` integer NOT NULL,
    `homework_id` integer NOT NULL,
    `last_updated_time` datetime NOT NULL
)
;
ALTER TABLE `myhomework_assessment` ADD CONSTRAINT `homework_id_refs_id_659a66f3` FOREIGN KEY (`homework_id`) REFERENCES `myhomework_homework` (`id`);
ALTER TABLE `myhomework_assessment` ADD CONSTRAINT `userA_id_refs_id_12ec8298` FOREIGN KEY (`userA_id`) REFERENCES `myhomework_user` (`id`);
ALTER TABLE `myhomework_assessment` ADD CONSTRAINT `userB_id_refs_id_12ec8298` FOREIGN KEY (`userB_id`) REFERENCES `myhomework_user` (`id`);
CREATE TABLE `myhomework_settings` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY
)
;
CREATE INDEX `myhomework_user_2619edb1` ON `myhomework_user` (`auth_user_id`);
CREATE INDEX `myhomework_user_425ae3c4` ON `myhomework_user` (`group_id`);
CREATE INDEX `myhomework_group_2e1d5b0e` ON `myhomework_group` (`administrator_id`);
CREATE INDEX `myhomework_homeworksubmitedinfo_60617b9e` ON `myhomework_homeworksubmitedinfo` (`homework_id`);
CREATE INDEX `myhomework_personalhomeworksubmited_410708cd` ON `myhomework_personalhomeworksubmited` (`homework_submited_info_id`);
CREATE INDEX `myhomework_personalhomeworksubmited_403f60f` ON `myhomework_personalhomeworksubmited` (`user_id`);
CREATE INDEX `myhomework_contribution_403f60f` ON `myhomework_contribution` (`user_id`);
CREATE INDEX `myhomework_teamworksubmited_410708cd` ON `myhomework_teamworksubmited` (`homework_submited_info_id`);
CREATE INDEX `myhomework_teamworksubmited_425ae3c4` ON `myhomework_teamworksubmited` (`group_id`);
CREATE INDEX `myhomework_assessment_3eec557f` ON `myhomework_assessment` (`userA_id`);
CREATE INDEX `myhomework_assessment_59860b94` ON `myhomework_assessment` (`userB_id`);
CREATE INDEX `myhomework_assessment_60617b9e` ON `myhomework_assessment` (`homework_id`);
COMMIT;
